<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
// | Author: your name
// +----------------------------------------------------------------------
namespace app\recruitmentEnterprise\logic;

use plugin\saiadmin\basic\BaseLogic;
use plugin\saiadmin\exception\ApiException;
use plugin\saiadmin\utils\Helper;
use app\recruitmentEnterprise\model\recruitmentEnterprise;
use plugin\saiadmin\service\OpenSpoutWriter;

/**
 * 招聘企业逻辑层
 */
class recruitmentEnterpriseLogic extends BaseLogic
{
    /**
     * 构造函数
     */
    public function __construct()
    {
        $this->model = new recruitmentEnterprise();
    }
    public function export($where = [])
    {
        $query = $this->search($where);
        // ->field('id,name,enterprise_id,sort,status,create_time');
        $data = $this->getAll($query);
        
        $file_name = '招聘企业数据.xlsx';
        $header = [ '企业名称', 'logo','企业人数', '联系人', '联系电话','邮箱', 
        '企业地址', '公司简介', '企业资质', '创建时间'];

        $filter = [
            // 'status' => [
            //     ['value' => 1, 'label' => '正常'],
            //     ['value' => 2, 'label' => '禁用']
            // ]
        ];
        $data_attr=[];
        foreach($data as $value){
           $data_attr[] = [
            'enterprise_name'=>$value['enterprise_name'],
            'institution_logo'=>$value['institution_logo'],
            'position_description'=>$value['enterprise_size'],
            'contact_person'=>$value['contact_person'],
            'contact_number'=>$value['contact_number'],
            'email'=>$value['email'],

            'enterprise_address'=>$value['enterprise_address'],
            'company_introduction'=>$value['company_introduction'],
            'enterprise_qualification'=>$value['enterprise_qualification'],
            'create_time'=>$value['create_time']
           ];
        }

        $writer = new OpenSpoutWriter($file_name);
        $writer->setWidth([20, 20, 20, 20, 20, 20,20,50,20,20]);
        $writer->setHeader($header);
        $writer->setData($data_attr, null, $filter);
        $file_path = $writer->returnFile();
        return response()->download($file_path, urlencode($file_name));
    }

}
